﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TouristAgencyDataLayer;
using System.Threading;

namespace TouristAgencyAsp
{
    public partial class MakePayment : System.Web.UI.Page
    {
        private string id;
        private bool redirect;

        protected void Page_Load(object sender, EventArgs e)
        {
            id = Request.Params["resId"];
            if (id != null)
            {
                Reservation r = Reservations.GetReservationById(Convert.ToInt32(id));
            
                if (r.ReservationType.ReservationType1 == "Confirmed")
                {
                    this.welcomeLbl.Text = "This reservation has already been confirmed";
                    redirect = true;
                }
                else if (!Page.IsPostBack)
                {    
                    this.resTypreDDL.Visible = true;
                    this.welcomeLbl.Text = "Select the new reservation type: ";
                    var types = ReservationTypes.GetReservationTypes().ToList();
                    this.resTypreDDL.DataSource = types;
                    this.resTypreDDL.DataTextField = "ReservationType1";
                    this.resTypreDDL.DataValueField = "ReservationTypeId";
                    this.resTypreDDL.SelectedIndex = 0;
                    this.saveBtn.Visible = true;
                    DataBind();
                }
            }
        }

        protected void saveBtn_Click(object sender, EventArgs e)
        {
            Reservation r = Reservations.GetReservationById(Convert.ToInt32(id));
            Reservations.UpdateReservation(r.ReservationId, r.TourId, Convert.ToInt32(this.resTypreDDL.SelectedValue), r.TotalPrice);

            Response.Redirect("~/Admin.aspx");
        }

        //protected void redirectTimer_Tick(object sender, EventArgs e)
        //{
        //    if (redirect)
        //    {
        //        Response.Redirect("~/Admin.aspx");
        //    }
        //}
    }
}